package game.adm.controller;
import java.util.List;

import game.adm.dao.dto.BetTypeDTO;
import game.adm.dao.dto.BonusDTO;
import game.adm.dao.dto.GameTypeDTO;
import game.adm.entity.BetTypeEntityManager;
import game.adm.entity.BonusEntityManager;
import game.adm.entity.GameTypeEntityManager;
import game.adm.struts.form.BonusForm;
import game.web.base.Constants;
import game.web.base.StringUtils;
import projectx.core.base.ProjectXSystemException;
import projectx.core.base.ProjectXUserException;
import projectx.transaction.TransactionHandler;
import projectx.web.base.ProjectXDbTrxController;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;

public class BonusController extends ProjectXDbTrxController {

	protected BonusController(UserContext uc, ProjectXForm form) {
		super(uc, form);
	}

	@Override
	public Object execute() throws ProjectXUserException,
			ProjectXSystemException {
		debugBegin();

		UserContext uc = getUc();
		BonusForm form = (BonusForm)getForm();
		String operator = form.getOperator();
		String updateip = StringUtils.getString(uc.get(Constants.ADM_REQUEST_IP));
		form.setIp(updateip);
		
		if("1".equals(operator)){    //初始化游戏奖金模版
			BonusEntityManager.initial(form);
		}else if("2".equals(operator)){     //查询游戏奖金模版	
			List<BonusDTO> list = BonusEntityManager.listAdminBonus(form);
			uc.put(Constants.ADM_BONUS_LIST, list);
		}else if("3".equals(operator)){     //查询某条游戏奖金记录
			BonusDTO dto = BonusEntityManager.getBonusByID(form.getBonusID());
			uc.put(Constants.ADM_BONUS_RECORD, dto);
		}else if("4".equals(operator)){     //更新游戏奖金设置
			BonusEntityManager.update(form);
		}else if("5".equals(operator)){     //查询玩家游戏奖金设置
			List<BonusDTO> list = BonusEntityManager.listUserBonus(form);
			uc.put(Constants.ADM_BONUS_LIST, list);
		}

		debugEnd();
		return null;
	}

	public static Object execute(UserContext uc, ProjectXForm form)
			throws ProjectXUserException, ProjectXSystemException {
		return TransactionHandler.call(new BonusController(uc, form));
	}
}
